package data;

import com.EntityName;
import com.google.appengine.api.datastore.Entity;

public class GuestMapping extends AbstractData{
	private long id = -1;
	private long displayId;
	private String guestString;
	private Guest guest;
	private long hotelId;
	private boolean status;
	private boolean avaliable;
	
	public GuestMapping(){}
	
	public GuestMapping(long id){
		this.id = id;
	}

	public long getId() {
		return id;
	}
	public long getDisplayId() {
		return displayId;
	}
	public void setDisplayId(long displayId) {
		this.displayId = displayId;
	}

	public Guest getGuest() {
		if (guest == null && !(guestString == null || guestString.isEmpty())&& !guestString.equals("0")) {
			Guest g = new Guest(Long.parseLong(guestString));
			g.LoadData();
			guest = g;
		}
		return guest;
	}

	public void setGuest(Guest guest) {
		this.guestString = String.format("%d", guest.getId());
		this.guest = guest;
	}

	public void setGuestString(String guestString) {
		this.guestString = guestString;
	}

	public void setId(long id) {
		this.id = id;
	}

	public long getHotelId() {
		return hotelId;
	}

	public void setHotelId(long hotelId) {
		this.hotelId = hotelId;
	}

	public boolean isStatus() {
		return status;
	}

	public void setStatus(boolean status) {
		this.status = status;
	}

	public boolean isAvaliable() {
		return avaliable;
	}

	public void setAvaliable(boolean avaliable) {
		this.avaliable = avaliable;
	}

	@Override
	public Entity getEntity() {
		Entity item;
		if(this.key == null)
			item = new Entity(EntityName.GuestMapping);
		else
			item = new Entity(this.key);

		item.setProperty("displayId", this.displayId);
		item.setProperty("guestId", this.guestString);
		item.setProperty("hotelId", this.hotelId);
		item.setProperty("status", this.status);
		item.setProperty("avaliable", this.avaliable);
		return item;
	}

	@Override
	public void setEntity(Entity entity) {
		this.displayId = (Long) entity.getProperty("displayId");
		this.guestString = (String) entity.getProperty("guestId");
		this.hotelId= (Long) entity.getProperty("hotelId");
		this.status= (Boolean) entity.getProperty("status");
		this.avaliable= (Boolean) entity.getProperty("avaliable");
		this.key = entity.getKey();
	}

	public void LoadData() {
		if (this.id > -1) {
			Entity entity = LoadData(EntityName.GuestMapping, this.id);
			setEntity(entity);
		}
	}
	
}
